package ru.picman.util;

public abstract class GreenThread
                      implements Runnable
{
	public GreenThread(String name) {
		this.name = name;
	}
	
	public GreenThread() {
		this(null);
	}
	
	//
	
	public boolean isRunning() {
		return running;
	}
	
	public String getName() {
		return name;
	}
	
	public long getSleepTime() {
		return sleepTime;
	}
	
	public void yield() {
		sleep(0L);
	}
	
	public void sleep(long ms) {
		sleepTime = (sleepTime == EOF ? EOF : Math.max(ms,0L));
	}
	
	public void stop() {
		sleepTime = EOF;
	}
	
	
	public String toString() {
		return name + "\t" + super.toString();
	}
	
	public abstract void run();
	
	//
	
	void setRunning(boolean running) {
		this.running = running;
	}
	
	//
	
	protected final String   name;
	
	private long             sleepTime;
	private boolean          running;
	
	public static final long EOF = -1L;
	
}
